layui.define(['table','treeTable'],function(exports){

	var $ = layui.$
	,form = layui.form
	,table = layui.table
	,setter = layui.setter
	,admin = layui.admin
	,treeTable = layui.treeTable
	var goodscode= $('#goodscode', parent.document).val();
	var system;
    var colsArr;
    var tableTitle;//表头标题
    var tableField;//表头标题 有隐藏
    var tableHead;//表头字段
    var tableSearch = {};//全局搜索条件


form.verify({	
  //我们既支持上述函数式的方式，也支持下述数组的形式
  //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]

  num: [
    /(^$)|^(^[0-9]\d*\.([0-9]{1,})$)|^[0-9]\d*$/
    ,'请输入整数或小数'
  ] 

});


    hiddendiv();
    function hiddendiv() {
        $("#table").show();
        $("#form").hide();
        loadtable();
    }

    function showdiv() {
        $("#table").hide();
        $("#form").show();
    }


    function loadtable() {
        colsArr = [
            {field: 'goodscode',hide:true, title: '所属系统', sort: false},
            {field: 'system',hide:true, title: '所属系统', sort: false},
            {field: 'systemname', title: '所属系统',width:100, sort: false},
            {field: 'minunit', title: '排面最小单位', sort: false},
            {field: 'minunitlength', title: '排面最小长度', sort: false},
            {field: 'minunit', title: '排面最小单位', sort: false},
            {field: 'remark', title: '备注', sort: false},
            {fixed: 'right', title: '操作', width: 70, toolbar: '#opeTable'}
        ];

        layui.each(colsArr, function (inx, val) {
            tableHead += val.hasOwnProperty('field') ? val.field : '-';
            tableHead += ',';
            tableTitle += val.hasOwnProperty('title') ? (val.hide ? '' : val.title + ',') : ',';
            tableField += val.hasOwnProperty('field') ? (val.hide ? '' : val.field + ',') : ',';
        })
        //tableHead是获取表字段
        tableHead = tableHead.substring(tableHead.indexOf(',') + 1, tableHead.length - 1);
        //导出时需要用到标题
        tableTitle = tableTitle.substring(tableTitle.indexOf(',') + 1, tableTitle.length - 1);
        //导出需要用到实际导出的字段
        tableField = tableField.substring(tableField.indexOf(',') + 1, tableField.length - 1);
        tableSearch["goodscode"] = goodscode;
        //用户管理
        table.render({
            elem: '#goods_order_table'
            , url: setter.host + '/goods_order/getSelectSystemSet'
            , cols: [colsArr]
            //,toolbar: 'true'
            //,defaultToolbar: ['print']
            , method: 'post'
            , contentType: 'application/json; charset=utf-8'
            ,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                search: tableSearch //查询字段
                ,headField:tableHead //表头字段
            }
            , page: true
            , limit: 10
            , limits: [10, 20,30]
            , height: '640'
            , text: {
                none: '暂无相关数据'
            }
        });
    }



//	------------------------------------------------------------------------------------------- 	
	var roleTable = treeTable.render({
		elem: '#LAY-role-list',
		tree: {
			iconIndex: 1,  // 折叠图标显示在第几列
			idName: 'id'  // 自定义id字段的名称
				,arrowType: 'arrow1' //箭头类型
		},
		parent_key: 'fatherid',
		height: '600',
		cols: colsArr = [
		                 {field: 'id', title: 'id',hide:true},
		                 {field: 'name', title: '名称'}
		                 ],
		                 method:'post',
		                 contentType:"application/json; charset=utf-8",
		                 url: setter.host+'/unite_platform/goods_system_set/roleList'
	});


    table.on('row(goods_order_table)', function(obj){
        id = obj.data.system;
        var delId = {};
        delId.id = obj.data.system;
        layui.admin.req({
            url: layui.setter.host+'/goods_system_supplier/roleList_dept'
            ,type:'post'
            ,dataType:'json'
            ,contentType: "application/json; charset=utf-8"
            ,data:JSON.stringify(delId)
            ,done: function(res){
                if (res.data.length==0){
                    $("#system").val(obj.data.systemname)
                    $.ajax({
                        url: setter.host+'/unite_platform/goods_system_set/getsystemInfo?id='+system+'&goodscode='+goodscode,
                        type:'get',
                        contentType: "application/json; charset=utf-8",
                        dataType:'json',
                        success: function(res){
                            showdiv()
                            //请求成功后
                            if(res.status == setter.response.statusCode.status_Success){
                                if(res.data.id[0]==undefined){
                                    $("#minunit").val('');
                                    $("#minunitlength").val('');
                                    $("#goodsset").val('');
                                    $("#maxset").val('');
                                }else{
                                    $("#minunit").val(res.data.id[0].minunit);
                                    $("#minunitlength").val(res.data.id[0].minunitlength);
                                    $("#goodsset").val(res.data.id[0].goodsset);
                                    $("#maxset").val(res.data.id[0].maxset);
                                }
                                form.render();
                            }else{
                                layer.msg(res.msg);
                            }
                        }
                    });
                }else {
                    hiddendiv()
                }
            }
        });
        var classcode;
        $("#tableDelete").on("click",function(){
            classcode=obj.data.classcode;
            layer.open({
                content: '是否删除？'
                ,btn: ['是', '否']
                ,yes: function(index, layero){
                    $.ajax({
                        url: setter.host+'/unite_platform/goods_class/deleteGoods?classcode='+classcode,
                        type:'get',
                        contentType: "application/json; charset=utf-8",
                        data:{},
                        dataType:'json',
                        success: function(res){
                            //请求成功后
                            if(res.status == setter.response.statusCode.status_Success){
                                layer.msg(res.msg);
                            }else{
                                layer.msg(res.msg);
                            }
                        }
                    });
                }
                ,btn3: function(index, layero){
                    return false;
                }
                ,cancel: function(){
                    return false;
                }
            });
        })

        var minunit;
        var minunitlength;
        var goodsset;
        var maxset;


//		$("#tableInsert").on("click",function(){
//
//			$("#fatherclassname").attr("readonly",false);
//			$("#classcode").attr("readonly",false);
//			fatherclassname = $("#classname").val();
//			$("#fatherclassname").val($("#classname").val());
//			fatherclasscode = $("#classcode").val();
//			$("#fatherclasscode").val($("#classcode").val());
//			$("#fatherclassname").attr("readonly",true);
//			$("#fatherclasscode").attr("readonly",true);
//			$("#classcode").val("");
//			$("#classname").attr("readonly",false);
//			$("#classname").val("");
//			$("#classremark").attr("readonly",false);
//			$("#classremark").val("");
//			dateType=$("#tableInsert").attr("data-type");
//		})
        $("#tableEdit").on("click",function(){
            $("#classname").attr("readonly",false);
            $("#classremark").attr("readonly",false);
            dateType=$("#tableEdit").attr("data-type");
        })
    });
	treeTable.on('row(LAY-role-list)', function(obj){
		system = obj.data.id;
        var delId = {};
        delId.id=obj.data.id;
        layui.admin.req({
            url: layui.setter.host+'/goods_system_supplier/roleList_dept'
            ,type:'post'
            ,dataType:'json'
            ,contentType: "application/json; charset=utf-8"
            ,data:JSON.stringify(delId)
            ,done: function(res){
                if (res.data.length==0){
                    $("#system").val(obj.data.name)
                    $.ajax({
                        url: setter.host+'/unite_platform/goods_system_set/getsystemInfo?id='+system+'&goodscode='+goodscode,
                        type:'get',
                        contentType: "application/json; charset=utf-8",
                        dataType:'json',
                        success: function(res){
                            showdiv()
                            //请求成功后
                            if(res.status == setter.response.statusCode.status_Success){
                                if(res.data.id[0]==undefined){
                                    $("#minunit").val('');
                                    $("#minunitlength").val('');
                                    $("#goodsset").val('');
                                    $("#maxset").val('');
                                }else{
                                    $("#minunit").val(res.data.id[0].minunit);
                                    $("#minunitlength").val(res.data.id[0].minunitlength);
                                    $("#goodsset").val(res.data.id[0].goodsset);
                                    $("#maxset").val(res.data.id[0].maxset);
                                }
                                form.render();
                            }else{
                                layer.msg(res.msg);
                            }
                        }
                    });
                }else {
                	hiddendiv()
				}
            }
        });
		var classcode;
		$("#tableDelete").on("click",function(){
			classcode=obj.data.classcode;
			layer.open({
				content: '是否删除？'
					,btn: ['是', '否']
			,yes: function(index, layero){
				$.ajax({
					url: setter.host+'/unite_platform/goods_class/deleteGoods?classcode='+classcode,
					type:'get',
					contentType: "application/json; charset=utf-8",
					data:{},
					dataType:'json',
					success: function(res){
						//请求成功后
						if(res.status == setter.response.statusCode.status_Success){
							layer.msg(res.msg);
						}else{
							layer.msg(res.msg);
						}
					}
				});
			}
			,btn3: function(index, layero){
				return false;
			}
			,cancel: function(){     
				return false;
			}
			});
		})
			
		var minunit;
		var minunitlength;
		var goodsset;
		var maxset;
		

//		$("#tableInsert").on("click",function(){
//			
//			$("#fatherclassname").attr("readonly",false);
//			$("#classcode").attr("readonly",false);
//			fatherclassname = $("#classname").val();
//			$("#fatherclassname").val($("#classname").val());
//			fatherclasscode = $("#classcode").val();
//			$("#fatherclasscode").val($("#classcode").val());
//			$("#fatherclassname").attr("readonly",true);
//			$("#fatherclasscode").attr("readonly",true);
//			$("#classcode").val("");
//			$("#classname").attr("readonly",false);
//			$("#classname").val("");
//			$("#classremark").attr("readonly",false);
//			$("#classremark").val("");
//			dateType=$("#tableInsert").attr("data-type");
//		})
		$("#tableEdit").on("click",function(){
			$("#classname").attr("readonly",false);
			$("#classremark").attr("readonly",false);
			dateType=$("#tableEdit").attr("data-type");
		})
	});
	
	

	function permission(OperationData,tr){
		admin.req({
			url: setter.host+'/adminmanager/role/permissionOperation'
			,type:'post'
				,contentType: "application/json; charset=utf-8"
					,data:JSON.stringify(OperationData)
					,done: function(res){
						//请求成功后
						if(res.status == setter.response.statusCode.status_Success){
							if(OperationData.operation=='confirm'){
								tr.find('button').text('取消');
								tr.find('button').attr('lay-event','cancle');
								tr.find('button').attr('class','layui-btn layui-btn-sm layui-btn-primary');
								tr.children('td[data-index="4"]').find('span').text('已授权');
								tr.children('td[data-index="4"]').find('span').css('color','green');
							}else if(OperationData.operation=='cancle'){
								tr.find('button').text('授权');
								tr.find('button').attr('lay-event','confirm');
								tr.find('button').attr('class','layui-btn layui-btn-sm');
								tr.children('td[data-index="4"]').find('span').text('未授权');
								tr.children('td[data-index="4"]').find('span').css('color','red');
							}
							layer.msg(res.msg);
							roleMenuDataTable.refresh();
						}else{
							layer.msg(res.msg);

						}
					}
		});
	}

	function permissionMenuData(OperationData,tr){
		admin.req({
			url: setter.host+'/adminmanager/role/permissionOperationData'
			,type:'post'
				,contentType: "application/json; charset=utf-8"
					,data:JSON.stringify(OperationData)
					,done: function(res){
						//请求成功后
						if(res.status == setter.response.statusCode.status_Success){
							if(OperationData.operation=='confirm'){
								tr.find('button').text('取消');
								tr.find('button').attr('lay-event','cancle');
								tr.find('button').attr('class','layui-btn layui-btn-sm layui-btn-primary');
								tr.children('td[data-index="3"]').find('span').text('已授权');
								tr.children('td[data-index="3"]').find('span').css('color','green');
							}else if(OperationData.operation=='cancle'){
								tr.find('button').text('授权');
								tr.find('button').attr('lay-event','confirm');
								tr.find('button').attr('class','layui-btn layui-btn-sm');
								tr.children('td[data-index="3"]').find('span').text('未授权');
								tr.children('td[data-index="3"]').find('span').css('color','red');
							}
							layer.msg(res.msg);
						}else{
							layer.msg(res.msg);
						}
					}
		});
	}



	$('.layui-btn').on('click', function(){
		var type = $(this).data('type');
		active[type] ? active[type].call(this) : '';
	});


    table.on('tool(goods_order_table)', function (obj) {
        var data = obj.data;
        if (obj.event === 'del') {
            layer.confirm('确认删除该行么', function (index) {
                // console.log("test")
                data.flag = 1;
                layui.admin.req({
                    url: layui.setter.host+'/goods_order/getSelectSystemSetDel'
                    ,type:'post'
                    ,dataType:'json'
                    ,contentType: "application/json; charset=utf-8"
                    ,data:JSON.stringify(data)
                    ,done: function(res){
                        //请求成功后
                        table.reload('goods_order_table');
                    }
                });

                layer.close(index);
            });
        }
    });
	
	


	var active = {
			backtable:function(){
				hiddendiv();
			},
			save:function(){
			form.on('submit(save)', function(data){
				var field = data.field;				

				var modifyUrL = layui.setter.host+'/goods_system_set/edit';

				minunit = $("#minunit").val();
				minunitlength = $("#minunitlength").val();
				goodsset = $("#goodsset").val();
				maxset = $("#maxset").val();

var json={'goodscode':goodscode,'system':system,'minunit':minunit,'minunitlength':minunitlength,'goodsset':goodsset,'maxset':maxset}
						

				layui.admin.req({
					url: modifyUrL
					,type:'post'
					,dataType:'json'
					,contentType: "application/json; charset=utf-8"
					,data:JSON.stringify(json)
					,success: function(res){
//						console.log(res);
						//请求成功后
						if(res.status == setter.response.statusCode.status_Success){
							layer.msg(res.msg);
						}else{
							layer.msg(res.msg);
						}
					}
					
				});								
			});
			$('[lay-filter="save"]').trigger('click');
		}	
		
			,batchdel: function(){
				var checkData = roleTable.checkStatus()
				//,checkData = checkStatus.data; //得到选中的数据
				if(checkData.length === 0){
					return layer.msg('请选择数据');
				}
				layer.prompt({
					formType: 1
					,title: '敏感操作，请验证当前用户口令'
				}, function(value, index_prompt){
					var command = layui.sessionData('layuiSession').command;
					if(value == command){
						layer.close(index_prompt);
						layer.confirm('确定删除吗？', function(index_confirm) {
							layer.close(index_confirm);
							//因为是单选项，只能选择一个
							if(checkData[0].hasOwnProperty('children')){
								layer.confirm('该选择的删除数据有子菜单,确定都删除吗?', {icon: 3, title:'提示'}, function(index_del){
									layer.close(index_del);
									del(checkData[0].roleId);
								});
							}else{
								del(checkData[0].roleId);
							}
						});
					}else{
						layer.msg('口令错误');
					}

				}); 
			}
	,add: function(){
		layer.open({
			type: 2
			,title: '添加角色'
				,content: setter.host+'/adminmanager/role/toAddRole'
				,area: ['500px', '540px']
		,btn: ['确定', '取消']
		,yes: function(index, layero){
			var iframeWindow = window['layui-layer-iframe'+ index]
			,submitID = 'LAY-role-add-submit'
				,submit = layero.find('iframe').contents().find('#'+ submitID);
			//监听提交
			iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
				//提交 Ajax 成功后，静态更新表格中的数据
				admin.req({
					url: setter.host+'/adminmanager/role/addRole'
					,type:'post'
						,dataType:'json'
							,contentType: "application/json; charset=utf-8"
								,data:JSON.stringify(data.field)  //获取提交的字段
								,done: function(res){
									//请求成功后
									if(res.status == setter.response.statusCode.status_Success){
										roleTable.refresh();
										layer.msg(res.msg);
										layer.close(index);
									}else{
										layer.msg(res.msg);
									}
								}
				});
			});  

			submit.trigger('click');
		}
		}); 
	}
	,edit: function(){
		var checkData = roleTable.checkStatus()
		if(checkData.length > 1){
			return layer.msg('只能选中编辑一行');
		}
		if(checkData.length ===0 ){
			return layer.msg('请选择一行数据进行编辑');
		}
		layer.open({
			type: 2
			,title: '编辑菜单'
				,content: setter.host+'/adminmanager/role/toEditRole'
				,area: ['440px', '540px']
		,btn: ['确定', '取消']
		,success:function(editFrame,index){
			var iframeWindow = window['layui-layer-iframe'+ index]
			,subBody = editFrame.find('iframe').contents();
			//subBody.find('select[name=type]').find("option[value='button']").attr("selected",true);
			subBody.find('input[name=name]').val(checkData[0].name);
			if(checkData[0].status=='启用')
				subBody.find('input[name=status]').attr('checked','checked');
			else
				subBody.find('input[name=status]');
		}
		,yes: function(index, layero){
			var iframeWindow = window['layui-layer-iframe'+ index]
			,submitID = 'LAY-role-edit-submit'
				,submit = layero.find('iframe').contents().find('#'+ submitID);
			//监听提交
			iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
				data.field.roleId = checkData[0].roleId;
				//提交 Ajax 成功后，静态更新表格中的数据
				admin.req({
					url: setter.host+'/adminmanager/role/editRole'
					,type:'post'
						,dataType:'json'
							,contentType: "application/json; charset=utf-8"
								,data:JSON.stringify(data.field)  //获取提交的字段
								,done: function(res){
									//请求成功后
									if(res.status == setter.response.statusCode.status_Success){
										roleTable.refresh();
										layer.msg(res.msg);
										layer.close(index);
									}else{
										layer.msg(res.msg);
									}
								}
				});
			});  
			submit.trigger('click');
		}
		});
	}
	,AddMenuPermission: function(){
		var checkData = roleMenuTable.checkStatus();
		var $table = $('.layui-fluid.layui-col-md8').find('div[lay-filter="LAY-role-menu-list"]').find('.ew-tree-table-box').find('table');

		if(checkData.length === 0){
			return layer.msg('请选择数据');
		}
		var menuIds = '';
		layui.each(checkData,function(inx,val){
			menuIds += val.menuId+',';
		});
		menuIds = menuIds.substring(0,menuIds.length-1);
		var OperationData = {};
		OperationData.menuId = menuIds;
		OperationData.roleId = roleMenu_roleId;
		OperationData.operation = 'confirm';
		BatchPermission(OperationData,$table);
	}
	,DetachMenuPermission: function(){
		var checkData = roleMenuTable.checkStatus();
		var $table = $('.layui-fluid.layui-col-md8').find('div[lay-filter="LAY-role-menu-list"]').find('.ew-tree-table-box').find('table');

		if(checkData.length === 0){
			return layer.msg('请选择数据');
		}
		var menuIds = '';
		layui.each(checkData,function(inx,val){
			menuIds += val.menuId+',';
		});
		menuIds = menuIds.substring(0,menuIds.length-1);
		var OperationData = {};
		OperationData.menuId = menuIds;
		OperationData.roleId = roleMenu_roleId;
		OperationData.operation = 'cancle';
		BatchPermission(OperationData,$table);
	}
	,AddDataPermission: function(){
		var checkData = roleMenuDataTable.checkStatus();
		var $table = $('.layui-fluid.layui-col-md8').find('div[lay-filter="LAY-role-menu-data-list"]').find('.ew-tree-table-box').find('table');
		if(checkData.length === 0){
			return layer.msg('请选择数据');
		}
		layui.each(checkData,function(inx,val){
			if(val.dtId == 0){
				layui.common.JSON_Remove(checkData,val);
			}
		});
		var isOne = '';
		var index1 = 0;
		var isType='';
		var menuIds = '';
		var names = '';
		layui.each(checkData,function(inx,val){
			if(val.dataId == 0)
				index1 = 1;
			if(inx!=index1 && isOne != val.dataId && val.dataId != 0){
				isOne = 'true';
				return isOne;
			}
			if(inx!=0 && isType != val.permissionStatus){
				isType = 'true';
				return isOne;
			}
			isType = val.permissionStatus;
			isOne= val.dataId;
			if(val.dataId != 0){
				menuIds += val.dataId+',';
				names += val.name+',';
			}
		});
		if(isOne == 'true'){
			return layer.msg('只能同时授权同一个菜单下的字段');
		}
		if(isType == 'true'){
			return layer.msg('不能同时授权不同类型的权限');
		}
		menuIds = menuIds.substring(0,menuIds.length-1);
		names = names.substring(0,names.length-1);
		var OperationData = {};
		OperationData.name = names;
		OperationData.menuId = menuIds;
		OperationData.roleId = roleMenu_roleId;
		OperationData.operation = 'confirm';
		BatchPermissionData(OperationData,$table);
	}
	,DetachDataPermission: function(){
		var checkData = roleMenuDataTable.checkStatus();
		var $table = $('.layui-fluid.layui-col-md8').find('div[lay-filter="LAY-role-menu-data-list"]').find('.ew-tree-table-box').find('table');

		if(checkData.length === 0){
			return layer.msg('请选择数据');
		}
		var index1 = 0;
		var isOne = '';
		var isType='';
		var menuIds = '';
		var names = '';
		layui.each(checkData,function(inx,val){
			if(val.dataId == 0)
				index1 = 1;
			if(inx!=index1 && isOne != val.dataId && val.dataId != 0){
				isOne = 'true';
				return isOne;
			}
			if(inx!=0 && isType != val.permissionStatus){
				isType = 'true';
				return isOne;
			}
			isType = val.permissionStatus;
			isOne= val.dataId;
			if(val.dataId != 0){
				menuIds += val.dataId+',';
				names += val.name+',';
			}
		});
		if(isOne == 'true'){
			return layer.msg('只能同时授权同一个菜单下的字段');
		}
		if(isType == 'true'){
			return layer.msg('不能同时授权不同类型的权限');
		}
		menuIds = menuIds.substring(0,menuIds.length-1);
		names = names.substring(0,names.length-1);
		var OperationData = {};
		OperationData.name = names;
		OperationData.menuId = menuIds;
		OperationData.roleId = roleMenu_roleId;
		OperationData.operation = 'cancle';
		BatchPermissionData(OperationData,$table);
	}
	,AddUser: function(){
		layer.open({
			type: 2
			,title: '添加  / 移除'
				,content: setter.host+'/adminmanager/role/toTransfor'
				,area: ['515px', '560px']
		,btn: ['确定', '取消']
		,success:function(editFrame,index){
			var iframeWindow = window['layui-layer-iframe'+ index]
			,subBody = editFrame.find('iframe').contents();
			subBody.find('input[name=roleId]').val(roleMenu_roleId);
		}
		,yes: function(index, layero){
			var iframeWindow = window['layui-layer-iframe'+ index]
			,subBody = layero.find('iframe').contents()
			,userIds = subBody.find('input[name=userId]').val()
			,OperationData = {};
			OperationData.userId = JSON.parse(userIds);
			OperationData.operation = 'AddUser';
			OperationData.roleId = roleMenu_roleId;
			BatchPermissionPerson(OperationData);
			layer.close(index);
		}
		});
	}
	,DetachUser: function(){
		var checkStatus = table.checkStatus('LAY-role-user-list')
		,checkData = checkStatus.data; 
		if(checkData.length === 0){
			return layer.msg('请选择数据');
		}
		var userIds = [];
		layui.each(checkData,function(inx,value){
			userIds.push(value.userId);
		});
		OperationData = {};
		OperationData.userId = userIds;
		OperationData.operation = 'DetachUser';
		OperationData.roleId = roleMenu_roleId;
		BatchPermissionPerson(OperationData);
	}
	}
	function del(roleId){
		admin.req({
			url: setter.host+'/adminmanager/role/batchdelRole'
			,type:'post'
				,contentType: "application/json; charset=utf-8"
					,data:'{"roleId":"'+roleId+'"}'
					,done: function(res){
						//请求成功后
						if(res.status == setter.response.statusCode.status_Success){
							roleTable.refresh();
							layer.msg(res.msg);
						}else{
							layer.msg(res.msg);
						}
					}
		});
	}
	function BatchPermission(OperationData,$table){
		admin.req({
			url: setter.host+'/adminmanager/role/permissionOperation'
			,type:'post'
				,contentType: "application/json; charset=utf-8"
					,data:JSON.stringify(OperationData)
					,done: function(res){
						//请求成功后
						if(res.status == setter.response.statusCode.status_Success){
							if(OperationData.operation=='confirm'){
								$table.find('input[name="ew_tb_checkbox_LAY-role-menu-list"]:checked').each(function () {
									var id = $(this).val();
									var $tr = $(this).parent('td').parent('tr');
									var isIndeterminate = $(this).next('.layui-form-checkbox').hasClass('ew-form-indeterminate');
									var isCheck = $(this).next('.layui-form-checkbox').hasClass('layui-form-checked');
									if (!isIndeterminate && isCheck) {
										$tr.find('button').text('取消')
										$tr.find('button').attr('lay-event','cancle');
										$tr.find('button').attr('class','layui-btn layui-btn-sm layui-btn-primary');
										$tr.children('td[data-index="4"]').find('span').text('已授权');
										$tr.children('td[data-index="4"]').find('span').css('color','green');
									}
								});
							}else if(OperationData.operation=='cancle'){
								$table.find('input[name="ew_tb_checkbox_LAY-role-menu-list"]:checked').each(function () {
									var id = $(this).val();
									var $tr = $(this).parent('td').parent('tr');
									var isIndeterminate = $(this).next('.layui-form-checkbox').hasClass('ew-form-indeterminate');
									var isCheck = $(this).next('.layui-form-checkbox').hasClass('layui-form-checked');
									if (!isIndeterminate && isCheck) {
										$tr.find('button').text('授权');
										$tr.find('button').attr('lay-event','confirm');
										$tr.find('button').attr('class','layui-btn layui-btn-sm');
										$tr.children('td[data-index="4"]').find('span').text('未授权');
										$tr.children('td[data-index="4"]').find('span').css('color','red');
									}
								});
							}
							layer.msg(res.msg);
							roleMenuDataTable.refresh();
						}else{
							layer.msg(res.msg);

						}
					}
		});
	}
	function BatchPermissionData(OperationData,$table){
		admin.req({
			url: setter.host+'/adminmanager/role/permissionOperationData'
			,type:'post'
				,contentType: "application/json; charset=utf-8"
					,data:JSON.stringify(OperationData)
					,done: function(res){
						//请求成功后
						if(res.status == setter.response.statusCode.status_Success){
							if(OperationData.operation=='confirm'){
								$table.find('input[name="ew_tb_checkbox_LAY-role-menu-data-list"]:checked').each(function () {
									var id = $(this).val();
									var $tr = $(this).parent('td').parent('tr');
									var isIndeterminate = $(this).next('.layui-form-checkbox').hasClass('ew-form-indeterminate');
									var isCheck = $(this).next('.layui-form-checkbox').hasClass('layui-form-checked');
									if (!isIndeterminate && isCheck) {
										$tr.find('button').text('取消')
										$tr.find('button').attr('lay-event','cancle');
										$tr.find('button').attr('class','layui-btn layui-btn-sm layui-btn-primary');
										$tr.children('td[data-index="3"]').find('span').text('已授权');
										$tr.children('td[data-index="3"]').find('span').css('color','green');
									}
								});
							}else if(OperationData.operation=='cancle'){
								$table.find('input[name="ew_tb_checkbox_LAY-role-menu-data-list"]:checked').each(function () {
									var id = $(this).val();
									var $tr = $(this).parent('td').parent('tr');
									var isIndeterminate = $(this).next('.layui-form-checkbox').hasClass('ew-form-indeterminate');
									var isCheck = $(this).next('.layui-form-checkbox').hasClass('layui-form-checked');
									if (!isIndeterminate && isCheck) {
										$tr.find('button').text('授权');
										$tr.find('button').attr('lay-event','confirm');
										$tr.find('button').attr('class','layui-btn layui-btn-sm');
										$tr.children('td[data-index="3"]').find('span').text('未授权');
										$tr.children('td[data-index="3"]').find('span').css('color','red');
									}
								});
							}
							layer.msg(res.msg);
						}else{
							layer.msg(res.msg);
						}
					}
		});
	}
	function BatchPermissionPerson(OperationData){
		admin.req({
			url: setter.host+'/adminmanager/role/permissionOperationPerson'
			,type:'post'
				,dataType:'json'
					,contentType: "application/json; charset=utf-8"
						,data:JSON.stringify(OperationData)  //获取提交的字段
						,done: function(res){
							//请求成功后
							if(res.status == setter.response.statusCode.status_Success){
								table.reload('LAY-role-user-list',{
									url: setter.host + '/adminmanager/role/selectUserByRole' 
									,where:{'roleId':roleMenu_roleId}
								});
							}else{
								layer.msg(res.msg);
							}
						}
		});
	}
	exports('role',{});
});
//---------------------------------------------------------------------------
//roleTable = table.render({
//elem: '#LAY-role-list1'
//,url:'/unite_platform/goods_class/getclasslabel'
//,cols: [[
//{type:'checkbox'}
//,{field:'id', width:80, title: 'ID', sort: true}
//,{field:'name', width:80, title: '用户名'}
//]]
//,page: true
//});



